import 'package:flame/components.dart';
import 'package:flame/game.dart';
import 'package:flame/gestures.dart';
import 'package:flame/palette.dart';
import 'package:flutter/widgets.dart';

class TapableComponent extends PositionComponent with Tapable {
  late Rect rect;
  late Paint color;

  @override
  Future<void>? onLoad() async {
    position = Vector2(200, 200);
    size = Vector2(100, 100);

    rect = Rect.fromLTWH(0, 0, 100, 100);

    print(rect);

    color = BasicPalette.white.paint();
  }

  @override
  void render(Canvas canvas) {
    canvas.drawRect(rect, color);
  }

  @override
  bool onTapUp(TapUpInfo event) {
    print('tap up');
    return true;
  }

  @override
  bool onTapDown(TapDownInfo event) {
    print('tap down');
    return true;
  }

  @override
  bool onTapCancel() {
    print('tap cancel');
    return true;
  }
}

class MyGame extends BaseGame with HasTapableComponents {
  @override
  Future<void> onLoad() async {
    debugMode = true;
    add(TapableComponent());
  }
}

main() {
  runApp(GameWidget(game: MyGame()));
}
